package net.tavion.angelboot.common.enums;

import org.apache.commons.lang3.StringUtils;

/**
 * @author : Rui
 * @date : 2019/6/8 11:12
 **/
public enum SystemCode {

    /**
     * Error Information
     */
    SUCCESS("0000", "SUCCESS"),

    HEADER_ERROR("9995", "请求头参数异常"),

    COMMON_AUTHORIZED_FAILURE("9996", "认证失败"),

    TOKEN_EXPIRED("9997", "TOKEN_EXPIRED"),
    ILLEGAL_REQUEST("9998", "ILLEGAL_REQUEST"),
    SYSTEM_ERROR("9999", "SYSTEM_ERROR"),

    ARGMENT_ERROR("9100", "调用参数异常"),
    BEAN_VALIDATION_ERROR("9110", "bean校验失败"),

    SYSTEM_CALL_ERROR("9190", "系统执行失败"),
    SYSTEM_404("9404", "未找到调用处理");

    private String code;
    private String message;


    SystemCode(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public String getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public static SystemCode codeOf(String code) {
        SystemCode messageCode;
        try {
            messageCode = SystemCode.valueOf(code);
        } catch (IllegalArgumentException e) {
            messageCode = SystemCode.SYSTEM_ERROR;
        }
        return messageCode;
    }

    public static boolean isSuccess(String code) {
        return StringUtils.equals("0000", code);
    }

    public static boolean isSuccess(SystemCode code) {
        return isSuccess(code.getCode());
    }
}
